package com.bbz.crawler.ip.proxy.pool.core.dataprocess;

import java.util.ArrayList;
import java.util.List;

import com.bbz.crawler.ip.proxy.pool.core.model.CrawlerProxyIp;

import us.codecraft.webmagic.Page;

/**
 * 西刺代理数据处理
 * 
 * @author binbin.a.zhang
 *
 */
public class XiCiDaiLiDataProcess {

	public List<CrawlerProxyIp> dataProcess(Page page) {
		List<String> ipInfo = page.getHtml().xpath("//div[@class='clearfix proxies']/table/tbody/tr/td/text()").all();
		List<CrawlerProxyIp> ipList = new ArrayList<>();

		int count = ipInfo.size() / 10;
		for (int i = 0; i < count; i++) {
			CrawlerProxyIp crawlerProxyIp = new CrawlerProxyIp();
			crawlerProxyIp.setIp(ipInfo.get(i * 10 + 1));
			crawlerProxyIp.setPort(ipInfo.get(i * 10 + 2));
			crawlerProxyIp.setType(ipInfo.get(i * 10 + 5));
			ipList.add(crawlerProxyIp);
		}
		return ipList;
	}

}
